Account Information

Obtaining Account Information

get_accounts(self, **params)

This is assuming you have multiple accounts for the user


In [1]:
import pandas as pd
import oandapy
import configparser

config = configparser.ConfigParser()
config.read('../config/config_v1.ini')
account_id = config['oanda']['account_id']
api_key = config['oanda']['api_key']

oanda = oandapy.API(environment="practice", 
                    access_token=api_key)

For a detailed explanation of the above, please refer to Rates Information.


In [2]:
response = oanda.get_accounts()
print(response)


{'accounts': [{'accountCurrency': 'SGD', 'marginRate': 0.02, 'accountId': 7173488, 'accountName': 'Primary'}]}

In [3]:
pd.DataFrame(response['accounts'])


Out[3]:
accountCurrency accountId accountName marginRate
0 SGD 7173488 Primary 0.02

Obtaining Specific Account Information

get_account(self, account_id, **params)


In [4]:
response = oanda.get_account(account_id)
print(response)


{'openOrders': 0, 'marginUsed': 978.1169, 'realizedPl': -11.5872, 'marginRate': 0.02, 'accountCurrency': 'SGD', 'openTrades': 25, 'marginAvail': 99184.5286, 'accountName': 'Primary', 'accountId': 7173488, 'unrealizedPl': 174.3933, 'balance': 99988.2522}

In [5]:
pd.Series(response)


Out[5]:
accountCurrency        SGD
accountId          7173488
accountName        Primary
balance            99988.3
marginAvail        99184.5
marginRate            0.02
marginUsed         978.117
openOrders               0
openTrades              25
realizedPl        -11.5872
unrealizedPl       174.393
dtype: object

In [6]:
print(response['unrealizedPl'])


174.3933